package com.hthl.consumer;

import com.hthl.config.ApplicationContextProvider;
import com.hthl.websocket.PollThread;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.concurrent.*;


/**
 * @author 刘青友
 */
@Component
@Slf4j
public class Receiver {

    StringRedisTemplate template;

    private static ExecutorService pool;


    public Receiver() {
        this.template = (StringRedisTemplate) ApplicationContextProvider.getBean("defaultStringRedisTemplate");
        pool = new ThreadPoolExecutor(3, 5, 10, TimeUnit.SECONDS, new ArrayBlockingQueue<>(1000),
                Executors.defaultThreadFactory(), new ThreadPoolExecutor.DiscardPolicy());
    }

    public void receiveMessage(String message) {
        pool.execute(new PollThread(message));
    }
}

